package com.fp.m7.client.presenter;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.place.PlaceRequest;
import net.customware.gwt.presenter.client.place.PlaceRequestEvent;

import com.fp.m7.client.place.HomePlace;
import com.fp.m7.client.place.LoginPlace;
import com.fp.m7.client.place.RegisterPlace;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.inject.Inject;

/**
 * Header presenter for a non-authorized user. Its display contains: Register, Login and Home buttons.
 * 
 * @author 7
 */
public class HeaderPublicPresenter extends HeaderPresenter<HeaderPublicPresenter.Display> {

    public interface Display extends HeaderPresenter.Display {

        HasClickHandlers getRegisterButton();

        HasClickHandlers getLoginButton();

        HasClickHandlers getHomeButton();

    }

    @Inject
    public HeaderPublicPresenter(Display display, EventBus eventBus) {
        super(display, eventBus);
    }

    @Override
    protected void onBind() {
        display.getHomeButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent paramClickEvent) {
                PlaceRequest req = new PlaceRequest(HomePlace.NAME);
                eventBus.fireEvent(new PlaceRequestEvent(req));
            }
        });

        display.getRegisterButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent paramClickEvent) {
                PlaceRequest req = new PlaceRequest(RegisterPlace.NAME);
                eventBus.fireEvent(new PlaceRequestEvent(req));
            }
        });

        display.getLoginButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent paramClickEvent) {
                PlaceRequest req = new PlaceRequest(LoginPlace.NAME);
                eventBus.fireEvent(new PlaceRequestEvent(req));
            }
        });
    }

    @Override
    protected void onUnbind() {
    }

    @Override
    protected void onRevealDisplay() {
    }
}
